from datetime import datetime, timedelta

def is_valid(date, format='%Y-%m-%d'):
    try:
        datetime.strptime(date, format)
        return True
    except ValueError:
        return False

def range_iterator(start_date, end_date, step=1, format='%Y-%m-%d'):
    start = datetime.strptime(start_date, format)
    end = datetime.strptime(end_date, format)
    return [(start + timedelta(i)).strftime(format) for i in range(0, (end - start).days + step, step)]

def length_iterator(start_date, length, step=1, format='%Y-%m-%d'):
    start = datetime.strptime(start_date, format)
    return [(start + timedelta(i)).strftime(format) for i in range(0, length * step, step)]

def get_date_range(days, format='%Y-%m-%d'):
    end_date = datetime.today()
    start_date = end_date - timedelta(days)
    return start_date.strftime(format), end_date.strftime(format)
